#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

int alternateDigitSum(int n)
{
    int sum = 0;
    int flag = 1;
    int count = 0;
    int k = n;
    while (k)
    {
        k /= 10;
        count++;
    }

    while (n)
    {
        if (count % 2 != 0)
        {
            sum += flag * (n % 10);
            flag = -flag;
            n /= 10;
        }
        if (count % 2 == 0)
        {
            sum += -flag * (n % 10);
            flag = -flag;
            n /= 10;
        }
    }
    return sum;
}